package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.LinkeBean;
import com.project.service.ILinkeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author(王思翰)
 * @Description(类的描述)
 * @Date(创建时间) 2021/7/21 17:18
 */
@Controller
@RequestMapping("linke")
public class LinkeController {
    @Autowired
    private ILinkeService service;

    @RequestMapping("/findAll")
    public String findAll(@RequestParam(value = "pageNO",defaultValue = "1") int pageNO, HttpServletRequest request){
        PageInfo<LinkeBean> pageInfo=service.findAll(pageNO);
        request.setAttribute("pageInfo",pageInfo);
        return "/html/linke/index.html";
    }

    @RequestMapping("/add")
    public String add(LinkeBean linkeBean){
        service.add(linkeBean);
        return "redirect:/linke/findAll";
    }

    @RequestMapping("del")
    public String del(int id){
        service.del(id);
        return "redirect:/linke/findAll";
    }

    @RequestMapping("findById")
    public String findById(int id, Model model){
        LinkeBean linkeBean=service.findById(id);
        model.addAttribute("linkeBean",linkeBean);
        return "/html/linke/update.html";
    }

    @RequestMapping("update")
    public String update(int id,String phone){
        service.update(id,phone);
        return "redirect:/linke/findAll";
    }
}
